using System;

namespace net.bistre.pfwl {
	/// <summary>
	/// Stores Settings for PFWL
	/// </summary>
	class Settings {
		public string InIP = "127.0.0.1";
		public string OutIP = "127.0.0.1";
		public int InPort = 0;
		public int OutPort = 0;
		public string LogFile = String.Empty;

		public static Settings LoadFromArgs(string[] args) {
			Settings settings = new Settings();

			for (int i=0; i < args.Length; i++) {
				switch (args[i]) {
					case "-inport":		// Port
						if (i < args.Length-1) {
							i++; settings.InPort = int.Parse(args[i]); }
						else {
							Console.WriteLine("Invalid -inport"); Environment.Exit(0); }
						break;

					case "-inip":		// IP
						if (i < args.Length-1) {
							i++; settings.InIP = args[i]; }
						else {
							Console.WriteLine("Invalid -inip"); Environment.Exit(0); }
						break;

					case "-outport":		// Port
						if (i < args.Length-1) {
							i++; settings.OutPort = int.Parse(args[i]); }
						else {
							Console.WriteLine("Invalid -inport"); Environment.Exit(0); }
						break;

					case "-outip":		// IP
						if (i < args.Length-1) {
							i++; settings.OutIP = args[i]; }
						else {
							Console.WriteLine("Invalid -inip"); Environment.Exit(0); }
						break;					

					case "-log":		// Log file
						if (i < args.Length-1) {
							i++; settings.LogFile = args[i]; }
						else {
							Console.WriteLine("Invalid -log"); Environment.Exit(0); }
						break;
					
					default:
						Console.WriteLine("Unknown option(s)"); Environment.Exit(0);
						break;
				}			
			}
			return settings;
		}
	}
}
